Program p1;
type
natural=10..20;
arrayNatMax=array[1..1000] of array [-3..4] of natural;
suit=(clubs,  diamonds,  hearts,  spades);
rec=record
	d:integer
end;
var a,b:natural;
		toto:array[-400..-200, natural, 1..1] of array[1..100] of suit;
		x:^natural;
		t:rec;
		i:record
			t:suit;
			m:rec
		end;


function inttostr(n:natural):string;
var temp:string;
begin
	while n<>0 do 
begin
	insert(chr((n mod 10)+48),temp,1);
	n:=n div 10;
end;
inttostr:= 1;
end;

procedure lololo(t:natural);
function test1(var titi, n:integer):char;
begin
end;

Procedure titi(var test1, m:integer);
begin
end;

begin
end;

Function cifdist(N,m:integer):natural;
var temp,st1,t:string;
I:integer;
begin

	st1:=inttostr(n);
	st2:=inttostr(m);
	for i:=1 to length(st1) do 
	if (pos(st1[i],st2)<>0) and (pos(st1[i],temp)=0)
	then temp:=temp+' '+st1[i];
	cifdist:=temp;
end;

Function cmmn(var M,n:natural; var b:real; var c:boolean):string;
var temp, st1, st2:string;
i:integer;
aux:char;
begin
	st1:=inttostr(n);
	st2:=inttostr(m);
	i:=9;
	while i>=0 do
	begin
		aux:=chr(i+48);
		if pos(aux,st1)<>0
		then begin
			temp:=temp+aux;
			delete(st1,pos(aux,st1),1);
		end;
		if pos(aux,st2)<>0
		then begin
			temp:=temp+aux;
			delete(st2,pos(aux,st2),1);
		end;
		if (pos(aux,st1)=0) and (pos(aux, st2)=0) then dec(i);
	end;
	cmmn:=temp;
end;

begin
	write('Dati numarul a: '); readln(a);
	write('Dati numarul b: '); readln(b);
	writeln(cifdist(a,b));
	writeln(cmmn(a,b));
end.
